package com.peng.leetcode.swordoffer;

import java.util.Arrays;

/**
 * Sword3FindRepeatNumber
 * 剑指 Offer 03. 数组中重复的数字
 * https://leetcode.cn/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/
 *
 * @author: lupeng6
 * @create: 2023/3/10 12:02
 */
public class Sword3FindRepeatNumber {

    public int findRepeatNumber(int[] nums) {
        int[] arr = new int[nums.length];
        Arrays.fill(arr, -1);
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            if (arr[num] > -1) {
                return num;
            }
            arr[num] = num;
        }
        return -1;
    }
}
